package com.lrkj.workorder.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.workorder.domain.WorkOrderLog;
import com.lrkj.workorder.service.IWorkOrderLogService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 工单日志Controller
 *
 * @author yajun_ren
 * @date 2022-04-25
 */
@RestController
@RequestMapping("/workorder/workOrderLog")
@Api(tags = "工单日志")
public class WorkOrderLogController extends BaseController
{
    @Autowired
    private IWorkOrderLogService workOrderLogService;

    /**
     * 查询工单日志列表
     */
    @ApiOperation(value = "查询工单日志列表", notes = "查询工单日志列表")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderLog workOrderLog)
    {
        startPage();
        this.changeParameter(workOrderLog.getParams());
        List<WorkOrderLog> list = workOrderLogService.selectWorkOrderLogList(workOrderLog);
        return getDataTable(list);
    }

    /**
     * 导出工单日志列表
     */
	@ApiOperation(value = "导出工单日志列表", notes = "导出工单日志列表")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:export')")
    @Log(title = "工单日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkOrderLog workOrderLog)
    {
        List<WorkOrderLog> list = workOrderLogService.selectWorkOrderLogList(workOrderLog);
        ExcelUtil<WorkOrderLog> util = new ExcelUtil<WorkOrderLog>(WorkOrderLog.class);
        return util.exportExcel(list, "工单日志数据");
    }

    /**
     * 获取工单日志详细信息
     */
	@ApiOperation(value = "获取工单日志详细信息", notes = "获取工单日志详细信息")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(workOrderLogService.selectWorkOrderLogById(id));
    }

    /**
     * 新增工单日志
     */
    @ApiOperation(value = "新增工单日志", notes = "新增工单日志")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:add')")
    @Log(title = "工单日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderLog workOrderLog)
    {
        return toAjax(workOrderLogService.insertWorkOrderLog(workOrderLog));
    }

    /**
     * 修改工单日志
     */
    @ApiOperation(value = "修改工单日志", notes = "修改工单日志")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:edit')")
    @Log(title = "工单日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderLog workOrderLog)
    {
        return toAjax(workOrderLogService.updateWorkOrderLog(workOrderLog));
    }

    /**
     * 删除工单日志
     */
    @ApiOperation(value = "删除工单日志", notes = "删除工单日志")
    @PreAuthorize("@ss.hasPermi('workorder:workOrderLog:remove')")
    @Log(title = "工单日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(workOrderLogService.deleteWorkOrderLogByIds(ids));
    }
}
